<?php
class Application_Model_Tickets extends Zend_Db_Table_Abstract
{
    protected $_name = 'tickets';
    protected $_primary = 'id';

	public function createTicket($params)
    {
        
         $data = array(
         	'date_ticket' => $params['date_ticket'],
            'time_start' => $params['time_start'],
         	'time_end' => $params['time_end'],
            'description' => $params['description'],
         	'user_id' => $params['user_id'],
         	'task_id' => $params['task_id'],
         	'hours' => $params['hours']
        );
		
        $this->insert($data);
    }

	public function getTicketList()
    {
        return $this->fetchAll()->toArray();
    }

	public function getTicket($id)
    {
        $where = $this->getAdapter()->quoteInto('id = ?', intval($id));
        $row = $this->fetchRow($where);

        if ($row) {
            return $row->toArray();
        } else {
            throw new Exception('Ticket not found');
        }
    }

    public function getTicketListByTask($task_id)
    {
        $where = $this->getAdapter()->quoteInto('task_id = ?', intval($task_id));

        return $this->fetchAll($where)->toArray();
    }

	public function getTicketListByUser($user_id)
    {
        $where = $this->getAdapter()->quoteInto('user_id = ?', intval($user_id));

        return $this->fetchAll($where)->toArray();
    }
}